package com.atguigu.gulimall.order.web;

import com.atguigu.gulimall.order.entity.OrderEntity;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * @Author : Jungle
 * @Description :
 */
@Controller
public class HelloController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @ResponseBody
    @GetMapping("/test/createOrder")
    public String createOrderTest(){
        //模拟订单成功
        OrderEntity entity = new OrderEntity();
        entity.setOrderSn(IdWorker.getTimeId());
        entity.setModifyTime(new Date());
        //发送消息
        //String exchange, String routingKey, Object message, CorrelationData correlationData
        rabbitTemplate.convertAndSend("order-event-exchange","order.create.order",entity);
        return "ok";


    }


    @GetMapping("/{page}.html")
    public String listPage(@PathVariable("page") String page) {
        //System.out.println(page);
        return page;
    }

}
